* **************************************************************************** *
* Sierra Leone - Social Signaling and Childhood Immunization                   *
* Knowledge about the Color of the Bracelet                                    *
* **************************************************************************** *
/*
** Purpose:    Create Table on Knowledge about the Color of the Bracelet
			   
*/
********************************************************************************
********************************************************************************


  use  "${Replicate_SocialSignals_dtaInter}/FirstOrderBeliefs_Data.dta", clear

  * Drop control group respondents for whom these questions are not relevant
  drop if treat1 == 1

  * ----------------------------------------------------------------------------
  * Label variables:
  lab var reason_knows1  "Mother showed me the bracelet"
  lab var reason_knows2  "Saw the bracelet on the child's arm"
  lab var reason_knows3  "Because everyone gets a bracelet at the clinic"
  lab var reason_knows4  "Saw the child getting the bracelet at the clinic"
  lab var reason_knows6  "Child has received the right amount of vaccines"
  lab var reason_knows9  "Because of the age of the child"
  lab var reason_knows10 "We talked about it"
  lab var reason_knows11 "We stay close together"
  lab var reason_knows12 "Just guessed"

  summ    reason_knows*

  * Summarize reasons for relevant sample of 3.5 to 12 months:
  summ    reason_knows2 reason_knows4 reason_knows3 reason_knows6                       if age_u1>= 107 & age_u1<=365

  summ    reason_knows1 reason_knows9 reason_knows10  reason_knows11 reason_knows12     if  age_u1>= 107 & age_u1<=365


  * Compute one combined variable of reason_knows2 reason_knows4
  * "Saw the bracelet on the child's arm" and "Saw the child getting the bracelet at the clinic"

  gen     saw_bracelet = 0       if reason_knows2 !=. & reason_knows4 !=.
  replace saw_bracelet = 1       if reason_knows2 == 1| reason_knows4 == 1

  tab     saw_bracelet           if  age_u1>= 107 & age_u1<=365


  gen     bracelet_oth = 0       if reason_knows3 !=. & reason_knows6 !=.
  replace bracelet_oth = 1       if reason_knows3 == 1| reason_knows6 == 1

  tab     bracelet_oth           if  age_u1>= 107 & age_u1<=365


  * ----------------------------------------------------------------------------
  * Demean control variables for the relevant sample of 3.5 to 12 months:

  tab     arm_anc, gen(anc)

  foreach anc_treat of numlist 2,3,4 {
    summ  anc`anc_treat'                                          if reason_knows2 !=. & age_u1>= 107 & age_u1<=365  & intervention_arm==2
    gen   anc`anc_treat'_dm = anc`anc_treat' - `r(mean)'          if reason_knows2 !=. & age_u1>= 107 & age_u1<=365
   }

  drop  edu*dm farm*dm relate*dm birth*dm age_u1*dm


  local FO_Controls = " mother_age_w01 farm edu2 edu3 farm_first_107 relate " + ///
                      " birth2 birth3 birth4 birth5 age_u1 "

  foreach control of local FO_Controls {
    summ  `control'                                               if reason_knows2!=. & age_u1>= 107 & age_u1<=365  & intervention_arm==2
    gen   `control'_dm = `control' - `r(mean)'                    if reason_knows2!=. & age_u1>= 107 & age_u1<=365
   }



  * ----------------------------------------------------------------------------
  * Run regression with control variables:

  local ANCVars        = " anc2_dm anc3_dm anc4_dm  "
  local MotherControls = " mother_age_w01_dm edu2_dm edu3_dm farm_dm relate_dm "
  local ChildControls  = " birth2_dm birth3_dm birth4_dm birth5_dm age_u1_dm "

  eststo clear
  foreach choice of numlist 2,4,3,6 {
		areg  reason_knows`choice'   treat3 treat4  `ChildControls'  `MotherControls' `ANCVars',  absorb(strata) vce(bootstrap , reps(${RepsNum}) seed(${seed}) cluster(clinic))
		eststo
		test   treat3 = treat4
		estadd scalar treat3_treat4 = r(p)
		estadd local Obs            = "`e(N)'"
		estadd scalar C_mean        = _b[_cons]
		eststo model_`choice'
    }

	esttab  ///
	model_2  model_4 model_3 model_6                                     ///
	using "${Replicate_SocialSignals_ATables}/Table_KnowBracelet_raw.tex",                     ///
	prehead("\begin{tabular}{l*{5}{c}} \toprule \\"                     ///
	"& \multicolumn{4}{c}{\textbf{How do you know that this baby has a green/yellow bracelet?}} \\ \\"   ///
	"\multicolumn{1}{l}{\textbf{\textbf{Dependent Variable:}}} & \multicolumn{1}{c}{\textbf{Saw bracelet on child}} & \multicolumn{1}{c}{\textbf{Saw child getting bracelet}} & \multicolumn{1}{c}{\textbf{Everyone gets a bracelet}} & \multicolumn{1}{c}{\textbf{Right \# of vaccines}}  \\")   ///
	scalars("C_mean       UI Group Mean"                                ///
	"Obs          Observations"                                 ///
	"treat3_treat4 p(S4 = S5)")                                 ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))              ///
	keep(_cons treat3 treat4)                                           ///
	varlabels(_cons "UI Group Mean")                                    ///
	sfmt(3) ${StarsOpt}  nomtitles                                      ///
	addnotes("") label b(3) se(3)  nobaselevels noconstant noobs        ///
	nolines posthead("\midrule") postfoot("\bottomrule \end{tabular}") tex  ///
	replace

	filefilter "${Replicate_SocialSignals_ATables}/Table_KnowBracelet_raw.tex"      ///
	"${Replicate_SocialSignals_ATables}/Table_KnowBracelet_Controls.tex", from("[1em]") to(" ") replace
	erase      "${Replicate_SocialSignals_ATables}/Table_KnowBracelet_raw.tex"


	* ----------------------------------------------------------------------------
	* outsheet p-values, with controls

	esttab  ///
	model_2  model_4 model_3 model_6                                     ///
	using "${Replicate_SocialSignals_ATables}/Table_KnowBracelet_raw.tex",                     ///
	prehead("\begin{tabular}{l*{5}{c}} \toprule \\"                     ///
	"& \multicolumn{4}{c}{\textbf{How do you know that this baby has a green/yellow bracelet?}} \\ \\"   ///
	"\multicolumn{1}{l}{\textbf{\textbf{Dependent Variable:}}} & \multicolumn{1}{c}{\textbf{Saw bracelet on child}} & \multicolumn{1}{c}{\textbf{Saw child getting bracelet}} & \multicolumn{1}{c}{\textbf{Everyone gets a bracelet}} & \multicolumn{1}{c}{\textbf{Right \# of vaccines}}  \\")   ///
	scalars("C_mean       UI Group Mean"                                ///
	"Obs          Observations"                                 ///
	"treat3_treat4 p(S4 = S5)")                                 ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))              ///
	keep(_cons treat3 treat4)                                           ///
	varlabels(_cons "UI Group Mean")                                    ///
	sfmt(3) ${StarsOpt}  nomtitles                                      ///
	addnotes("") label b(3) p(3)  nobaselevels noconstant noobs        ///
	nolines posthead("\midrule") postfoot("\bottomrule \end{tabular}") tex  ///
	replace

	filefilter "${Replicate_SocialSignals_ATables}/Table_KnowBracelet_raw.tex"      ///
	"${Replicate_SocialSignals_ATables}/Table_KnowBracelet_Controls_pvals.tex", from("[1em]") to(" ") replace
	erase	"${Replicate_SocialSignals_ATables}/Table_KnowBracelet_raw.tex"
	erase "${Replicate_SocialSignals_ATables}/Table_KnowBracelet_Controls_pvals.tex"



* ******************************************************************************
* End of the Dofile !!!
* ******************************************************************************
